<template>
  <div>
    <!-- 头部滑动 -->
    <div class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
      <div class="mui-scroll">
        <a class="mui-control-item mui-active" @click="getImglist(0)">
              全部
        </a>
        <a class="mui-control-item" v-for="item in headList" :key="item.id" @click="getImglist(item.id)">
            {{item.title}}
        </a>
      </div>
    </div>

    <!-- 图片列表区域 -->
    <ul class="imgBox">
    
         <router-link :to="'/photo/info/'+item.id" v-for="item in imgList" :key="item.id" tag="li">
            <img v-lazy="item.img_url" >
            <div class="info">
              <h3>{{item.title}}</h3>
              <p>{{item.zhaiyao}}</p>
            </div>
        </router-link>

    </ul>
  </div>
</template>

<script>
import mui from "../../libs/mui/js/mui.min.js";
import { Toast } from "mint-ui";

export default {
  data() {
    return {
      headList: [],
      imgList: []
    };
  },
  created() {
    this.getHeadlist();
    this.getImglist(0);
  },
  mounted() {
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  methods: {
    // 获取滚动区域的内容
    getHeadlist() {
      this.$http.get("api/getimgcategory").then(res => {
        if (res.body.status === 0) {
          this.headList = res.body.message;
        } else {
          Toast("图片列表加载失败");
        }
      });
    },
    // 获取图片区域的内容
    getImglist(id) {
      this.$http.get("api/getimages/" + id).then(res => {
        if (res.body.status === 0) {
          this.imgList = res.body.message;
        }
      });
    }
  }
};
</script>

<style scoped lang='less'>
* {
  touch-action: pan-y;
}
.mui-scroll-wrapper
  .mui-slider-indicator
  .mui-segmented-control
  .mui-segmented-control-inverted {
  padding: 0 10px;
}
.imgBox {
  margin: 0;
  list-style: none;
  padding: 20px;
  background-color: rgb(236, 234, 234);

  li {
    height: 385px;
    text-align: center;
    display: block;
    position: relative;
    margin: 10px 0;
    box-shadow: 0px 0px 10px rgb(0, 0, 0);
    border-radius: 10px;
    img {
      width: 100%;
      border-radius: 10px;
      vertical-align: middle;
    }
    img[lazy="loading"] {
      width: 40px;
      height: 200px;
      margin: auto;
    }
    .info {
      border-radius: 10px;
      padding: 0 5px;
      background: rgba(0, 0, 0, 0.4);
      position: absolute;
      bottom: 0px;
      left: 0;
      right: 0;
      text-align: left;
      max-height: 82px;
      h3 {
        color: #fff;
        font-size: 14px;
      }
      p {
        border-radius: 10px;

        color: #fff;
        font-size: 10px;
      }
    }
  }
}
</style>